<html>
<head><meta charset="utf-8"><title>Help getting to a generic type on a function call · clippy · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/index.html">clippy</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Help.20getting.20to.20a.20generic.20type.20on.20a.20function.20call.html">Help getting to a generic type on a function call</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="218044934"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Help%20getting%20to%20a%20generic%20type%20on%20a%20function%20call/near/218044934" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nick12 <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Help.20getting.20to.20a.20generic.20type.20on.20a.20function.20call.html#218044934">(Nov 26 2020 at 23:25)</a>:</h4>
<p>Hi! I'm trying to work on <a href="https://github.com/rust-lang/rust-clippy/issues/6381">https://github.com/rust-lang/rust-clippy/issues/6381</a></p>
<p>I have an Expr for a function call to size_of::&lt;T&gt;(), and I want to get the generic type (To TyS::same_type with some other type)</p>
<p>I've been having some trouble finding how to do it, I saw Adt is used for generic structs, and that the MethodCall Expr kind has generics in the PathSegment, but nothing for Call</p>



<a name="218049556"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Help%20getting%20to%20a%20generic%20type%20on%20a%20function%20call/near/218049556" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nick12 <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Help.20getting.20to.20a.20generic.20type.20on.20a.20function.20call.html#218049556">(Nov 27 2020 at 01:19)</a>:</h4>
<p>I found <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/hir/struct.PathSegment.html">https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/hir/struct.PathSegment.html</a> but I think that only works if f::&lt;T&gt; is used (And not if it's inferred)</p>



<a name="218055564"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Help%20getting%20to%20a%20generic%20type%20on%20a%20function%20call/near/218055564" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Michael Wright <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Help.20getting.20to.20a.20generic.20type.20on.20a.20function.20call.html#218055564">(Nov 27 2020 at 04:13)</a>:</h4>
<p>Don't try to determine the type yourself. Use the TypeckResults instead. It should have a method to do that. Maybe  <code>node_substs</code> is the method you want. e.g <code>let substs = cx.typeck_results().node_substs(hir_id);</code>. Search the Clippy source for examples of where it's used.</p>



<a name="218074336"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Help%20getting%20to%20a%20generic%20type%20on%20a%20function%20call/near/218074336" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nick12 <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Help.20getting.20to.20a.20generic.20type.20on.20a.20function.20call.html#218074336">(Nov 27 2020 at 10:05)</a>:</h4>
<p>Thank you! I'll do that. that sounds like exactly what I needed</p>
<p>I was using the TypeckResults to evaluate the other type and didn't realize I also needed it for the substitutions</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>